// Upgrade NOTE: replaced 'mul(UNITY_MATRIX_MVP,*)' with 'UnityObjectToClipPos(*)'

Shader "Skybox/Procedural" {
Properties {
[KeywordEnum(None, Simple, High Quality)]  _SunDisk ("Sun", Float) = 2
 _SunSize ("Sun Size", Range(0,1)) = 0.04
 _AtmosphereThickness ("Atmoshpere Thickness", Range(0,5)) = 1
 _SkyTint ("Sky Tint", Color) = (0.5,0.5,0.5,1)
 _GroundColor ("Ground", Color) = (0.369,0.349,0.341,1)
 _Exposure ("Exposure", Range(0,8)) = 1.3
}
SubShader { 
 Tags { "QUEUE"="Background" "RenderType"="Background" "PreviewType"="Skybox" }
 Pass {
  Tags { "QUEUE"="Background" "RenderType"="Background" "PreviewType"="Skybox" }
  ZWrite Off
  Cull Off
  GpuProgramID 1581
CGPROGRAM
//#pragma target 4.0

#pragma vertex vert
#pragma fragment frag

#include "UnityCG.cginc"
#define conv_mxt4x4_0(mat4x4) float4(mat4x4[0].x,mat4x4[1].x,mat4x4[2].x,mat4x4[3].x)
#define conv_mxt4x4_1(mat4x4) float4(mat4x4[0].y,mat4x4[1].y,mat4x4[2].y,mat4x4[3].y)
#define conv_mxt4x4_2(mat4x4) float4(mat4x4[0].z,mat4x4[1].z,mat4x4[2].z,mat4x4[3].z)


#define CODE_BLOCK_VERTEX
//uniform float4 _WorldSpaceLightPos0;
//uniform float4x4 UNITY_MATRIX_MVP;
//uniform float4x4 unity_ObjectToWorld;
//uniform float4 unity_ColorSpaceDouble;
uniform float _Exposure;
uniform float3 _GroundColor;
uniform float3 _SkyTint;
uniform float _AtmosphereThickness;
struct appdata_t
{
    float4 vertex :POSITION;
};

struct OUT_Data_Vert
{
    float xlv_TEXCOORD0 :TEXCOORD0;
    float3 xlv_TEXCOORD1 :TEXCOORD1;
    float3 xlv_TEXCOORD2 :TEXCOORD2;
    float4 vertex :SV_POSITION;
};

struct v2f
{
    float xlv_TEXCOORD0 :TEXCOORD0;
    float3 xlv_TEXCOORD1 :TEXCOORD1;
    float3 xlv_TEXCOORD2 :TEXCOORD2;
};

struct OUT_Data_Frag
{
    float4 color :SV_Target0;
};

OUT_Data_Vert vert(appdata_t in_v)
{
    OUT_Data_Vert out_v;
    float3 cOut_1;
    float3 cIn_2;
    float far_3;
    float kKr4PI_4;
    float kKrESun_5;
    float3 kSkyTintInGammaSpace_6;
    float4 tmpvar_7;
    float tmpvar_8;
    tmpvar_7 = UnityObjectToClipPos(in_v.vertex);
    float3 tmpvar_9;
    if((unity_ColorSpaceDouble.x>2))
    {
        tmpvar_9 = pow(_SkyTint, float3(0.4545454, 0.4545454, 0.4545454));
    }
    else
    {
        tmpvar_9 = _SkyTint;
    }
    kSkyTintInGammaSpace_6 = tmpvar_9;
    float3 tmpvar_10;
    float _tmp_dvx_60 = (1 / pow(lerp(float3(0.5, 0.42, 0.325), float3(0.8, 0.72, 0.625), (float3(1, 1, 1) - kSkyTintInGammaSpace_6)), float3(4, 4, 4)));
    tmpvar_10 = float3(_tmp_dvx_60, _tmp_dvx_60, _tmp_dvx_60);
    float tmpvar_11;
    float tmpvar_12;
    tmpvar_12 = pow(_AtmosphereThickness, 2.5);
    tmpvar_11 = (0.05 * tmpvar_12);
    kKrESun_5 = tmpvar_11;
    float tmpvar_13;
    tmpvar_13 = (0.03141593 * tmpvar_12);
    kKr4PI_4 = tmpvar_13;
    float3x3 tmpvar_14;
    tmpvar_14[0] = conv_mxt4x4_0(unity_ObjectToWorld).xyz;
    tmpvar_14[1] = conv_mxt4x4_1(unity_ObjectToWorld).xyz;
    tmpvar_14[2] = conv_mxt4x4_2(unity_ObjectToWorld).xyz;
    float3 tmpvar_15;
    tmpvar_15 = normalize(mul(tmpvar_14, in_v.vertex.xyz));
    far_3 = 0;
    if((tmpvar_15.y>=0))
    {
        float3 frontColor_16;
        float3 samplePoint_17;
        far_3 = (sqrt(((1.050625 + (tmpvar_15.y * tmpvar_15.y)) - 1)) - tmpvar_15.y);
        float tmpvar_18;
        tmpvar_18 = (1 - (dot(tmpvar_15, float3(0, 1.0001, 0)) / 1.0001));
        float tmpvar_19;
        tmpvar_19 = (exp((-0.00287 + (tmpvar_18 * (0.459 + (tmpvar_18 * (3.83 + (tmpvar_18 * (-6.8 + (tmpvar_18 * 5.25))))))))) * 0.2460318);
        float tmpvar_20;
        tmpvar_20 = (far_3 / 2);
        float tmpvar_21;
        tmpvar_21 = (tmpvar_20 * 40.00004);
        float3 tmpvar_22;
        tmpvar_22 = (tmpvar_15 * tmpvar_20);
        float3 tmpvar_23;
        tmpvar_23 = (float3(0, 1.0001, 0) + (tmpvar_22 * 0.5));
        float tmpvar_24;
        tmpvar_24 = sqrt(dot(tmpvar_23, tmpvar_23));
        float tmpvar_25;
        tmpvar_25 = exp((160.0002 * (1 - tmpvar_24)));
        float tmpvar_26;
        tmpvar_26 = (1 - (dot(_WorldSpaceLightPos0.xyz, tmpvar_23) / tmpvar_24));
        float tmpvar_27;
        tmpvar_27 = (1 - (dot(tmpvar_15, tmpvar_23) / tmpvar_24));
        float _tmp_dvx_61 = (exp(((-clamp((tmpvar_19 + (tmpvar_25 * ((0.25 * exp((-0.00287 + (tmpvar_26 * (0.459 + (tmpvar_26 * (3.83 + (tmpvar_26 * (-6.8 + (tmpvar_26 * 5.25)))))))))) - (0.25 * exp((-0.00287 + (tmpvar_27 * (0.459 + (tmpvar_27 * (3.83 + (tmpvar_27 * (-6.8 + (tmpvar_27 * 5.25))))))))))))), 0, 50)) * ((tmpvar_10 * kKr4PI_4) + 0.01256637))) * (tmpvar_25 * tmpvar_21));
        frontColor_16 = float3(_tmp_dvx_61, _tmp_dvx_61, _tmp_dvx_61);
        samplePoint_17 = (tmpvar_23 + tmpvar_22);
        float tmpvar_28;
        tmpvar_28 = sqrt(dot(samplePoint_17, samplePoint_17));
        float tmpvar_29;
        tmpvar_29 = exp((160.0002 * (1 - tmpvar_28)));
        float tmpvar_30;
        tmpvar_30 = (1 - (dot(_WorldSpaceLightPos0.xyz, samplePoint_17) / tmpvar_28));
        float tmpvar_31;
        tmpvar_31 = (1 - (dot(tmpvar_15, samplePoint_17) / tmpvar_28));
        frontColor_16 = (frontColor_16 + (exp(((-clamp((tmpvar_19 + (tmpvar_29 * ((0.25 * exp((-0.00287 + (tmpvar_30 * (0.459 + (tmpvar_30 * (3.83 + (tmpvar_30 * (-6.8 + (tmpvar_30 * 5.25)))))))))) - (0.25 * exp((-0.00287 + (tmpvar_31 * (0.459 + (tmpvar_31 * (3.83 + (tmpvar_31 * (-6.8 + (tmpvar_31 * 5.25))))))))))))), 0, 50)) * ((tmpvar_10 * kKr4PI_4) + 0.01256637))) * (tmpvar_29 * tmpvar_21)));
        samplePoint_17 = (samplePoint_17 + tmpvar_22);
        cIn_2 = (frontColor_16 * (tmpvar_10 * kKrESun_5));
        cOut_1 = (frontColor_16 * 0.02);
    }
    else
    {
        float3 frontColor_1_32;
        far_3 = (-0.0001 / min(-0.001, tmpvar_15.y));
        float3 tmpvar_33;
        tmpvar_33 = (float3(0, 1.0001, 0) + (far_3 * tmpvar_15));
        float tmpvar_34;
        float tmpvar_35;
        tmpvar_35 = (1 - dot((-tmpvar_15), tmpvar_33));
        tmpvar_34 = (0.25 * exp((-0.00287 + (tmpvar_35 * (0.459 + (tmpvar_35 * (3.83 + (tmpvar_35 * (-6.8 + (tmpvar_35 * 5.25))))))))));
        float tmpvar_36;
        tmpvar_36 = (1 - dot(_WorldSpaceLightPos0.xyz, tmpvar_33));
        float tmpvar_37;
        tmpvar_37 = (far_3 / 2);
        float3 tmpvar_38;
        tmpvar_38 = (float3(0, 1.0001, 0) + ((tmpvar_15 * tmpvar_37) * 0.5));
        float tmpvar_39;
        tmpvar_39 = exp((160.0002 * (1 - sqrt(dot(tmpvar_38, tmpvar_38)))));
        float3 tmpvar_40;
        float _tmp_dvx_62 = exp(((-clamp(((tmpvar_39 * ((0.25 * exp((-0.00287 + (tmpvar_36 * (0.459 + (tmpvar_36 * (3.83 + (tmpvar_36 * (-6.8 + (tmpvar_36 * 5.25)))))))))) + tmpvar_34)) - (0.9996001 * tmpvar_34)), 0, 50)) * ((tmpvar_10 * kKr4PI_4) + 0.01256637)));
        tmpvar_40 = float3(_tmp_dvx_62, _tmp_dvx_62, _tmp_dvx_62);
        frontColor_1_32 = (tmpvar_40 * (tmpvar_39 * (tmpvar_37 * 40.00004)));
        cIn_2 = (frontColor_1_32 * ((tmpvar_10 * kKrESun_5) + 0.02));
        float3 tmpvar_41;
        tmpvar_41 = clamp(tmpvar_40, float3(0, 0, 0), float3(1, 1, 1));
        cOut_1 = tmpvar_41;
    }
    tmpvar_8 = ((-tmpvar_15.y) / 0.02);
    float3 light_42;
    light_42 = _WorldSpaceLightPos0.xyz;
    float3 ray_43;
    ray_43 = (-tmpvar_15);
    float tmpvar_44;
    tmpvar_44 = dot(light_42, ray_43);
    out_v.vertex = tmpvar_7;
    out_v.xlv_TEXCOORD0 = tmpvar_8;
    out_v.xlv_TEXCOORD1 = (_Exposure * (cIn_2 + (_GroundColor * cOut_1)));
    out_v.xlv_TEXCOORD2 = (_Exposure * (cIn_2 * (0.75 + (0.75 * (tmpvar_44 * tmpvar_44)))));
    return out_v;
}

#define CODE_BLOCK_FRAGMENT
OUT_Data_Frag frag(v2f in_f)
{
    OUT_Data_Frag out_f;
    float4 tmpvar_1;
    tmpvar_1.w = 1;
    float _tmp_dvx_63 = clamp(in_f.xlv_TEXCOORD0, 0, 1);
    tmpvar_1.xyz = lerp(in_f.xlv_TEXCOORD2, in_f.xlv_TEXCOORD1, float3(_tmp_dvx_63, _tmp_dvx_63, _tmp_dvx_63));
    out_f.color = tmpvar_1;
    return out_f;
}


ENDCG

}
}
Fallback Off
}